﻿'Description:叶片批次类，批次相关的后台方法
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:Wangjh 
'create Date:20211018
'Rewriter:
'Rewrite Date:
Imports DatabaseAccess.DBUtility
Imports BusinessRule.DTO
Imports System.Text
Imports External.APICalling
Imports System.Linq

Public Class MakeCalendarBusiness
    Public Function SaveOrUpdateMainCaData(ByVal para As DataRow) As uMESProcessResult
        Dim result = New uMESProcessResult()
        Try
            Dim strsql As New StringBuilder
            strsql.Clear()
            strsql.AppendLine("INSERT INTO MAKECALENDAR(MAKECALENDARID,CREATEEMPLOYEEID,DESCRIPTION,ISUSE,MAKECALENDARNAME,CREATEDATE) VALUES(sys_guid(),")
            strsql.AppendFormat("'{0}',", para("CREATEEMPLOYEEID"))
            strsql.AppendFormat("'{0}',", para("DESCRIPTION"))
            strsql.AppendFormat("'{0}',", para("ISUSE"))
            strsql.AppendFormat("'{0}',", para("MAKECALENDARNAME"))
            strsql.AppendFormat("{0})", "sysdate")
            DatabaseHelper.ExecuteSql(strsql.ToString())
            result.Result = True
            result.Message = "添加成功"
        Catch ex As Exception
            result.Message = ex.Message
            result.Result = False
        End Try
        Return result
    End Function

    ''' <summary>
    ''' 插入表
    ''' </summary>
    ''' <param name="tableName"></param>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function BatchInsertTableInfo(ByVal tableName As String, ByVal paraList As Object) As Boolean
        BatchInsertTableInfo = False
        If paraList.Count = 0 Then
            Exit Function
        End If
        Dim strsql As New StringBuilder
        strsql.AppendLine("insert ALL ")
        For Each para In paraList
            strsql.AppendLine(FillInsertTableInfo(tableName, para))
        Next
        strsql.AppendLine("select 1 from dual")
        If DatabaseHelper.ExecuteSql(strsql.ToString) > 0 Then
            BatchInsertTableInfo = True
        End If
    End Function

    Function FillInsertTableInfo(ByVal tableName As String, ByVal para As Dictionary(Of String, Object)) As String
        Dim strSql As String = " into " + tableName + " ( "
        Dim n = 0
        For Each key As String In para.Keys
            strSql += key + ","

            If n = para.Keys.Count - 1 Then
                strSql = strSql.Substring(0, strSql.Length - 1) + ")"
            End If
            n += 1
        Next
        n = 0
        For Each key As String In para.Keys
            If n = 0 Then
                strSql += " values ("
            End If
            If para(key).GetType.ToString() = "System.DateTime" Then
                strSql += "to_date('" + Date.Parse(para(key)).ToString("yyyy/MM/dd") + "','yyyy/MM/dd'),"
            Else
                If String.IsNullOrWhiteSpace(para(key)) Then
                    strSql += "'',"
                Else
                    strSql += para(key) + ","
                End If
            End If

            If n = para.Count - 1 Then
                strSql = strSql.Substring(0, strSql.Length - 1) + ")"
            End If
            n += 1
        Next
        Return strSql
    End Function


End Class


